package org.komarichin.services;

import org.komarichin.beans.IFile;
import org.komarichin.beans.dao.IFileDAO;
import org.komarichin.beans.service.IFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;

/**
 * User: Mykhaylo Komarichyn
 * Date: 31.12.2009
 * Time: 12:33:57
 */
@Service
public class FileService<PK> implements IFileService<PK> {
    private static final long serialVersionUID = -6497112028992926214L;

    private static final Logger log = LoggerFactory.getLogger(FileService.class);

    @Autowired
    private IFileDAO<IFile<PK>, PK> fileDAO;

    @Override
    public IFile<PK> createBlank() {
        return fileDAO.newInstance();
    }

    @Override
    public IFile<PK> save(IFile<PK> file) {
        return fileDAO.save(file);
    }

    @Override
    public IFile<PK> save(IFile<PK> file, IFile<PK> folder) {
        return fileDAO.save(file, folder);
    }

    @Override
    public void saveOrUpdate(IFile<PK> file) {
        fileDAO.saveOrUpdate(file);
    }

    @Override
    public void delete(IFile<PK> file) {
        delete(file.getId());
    }

    @Override
    public void delete(PK id) {
        fileDAO.remove(id);
    }

    @Override
    public IFile<PK> getFile(PK id) {
        return fileDAO.findById(id);
    }

    @Override
    public Collection<IFile<PK>> getFiles(String folderName) {
        return fileDAO.getFiles(folderName);
    }

    @Override
    public Collection<IFile<PK>> getFilesAndFolders(String folderName) {
        return fileDAO.getFilesAndFolders(folderName);
    }

    @Override
    public boolean exists(String fileName, String folder) {
        return fileDAO.exists(fileName, folder);
    }

    @Override
    public boolean isFolderEmpty(String folder) {
        return fileDAO.isFolderEmpty(folder);
    }

    @Override
    public Collection<String> getFolders(String currentFolder) {
        return fileDAO.getFolders(currentFolder);
    }
}
